package Sort;

import java.util.Arrays;

/**
 * @Classname 冒泡排序
 * @Description TODO
 * @Date 2023/2/16 20:59
 * @Created by xjl
 */
public class 冒泡排序 {
    /**
     * @description 冒泡排序
     * @param: Array
     * @date: 2023/2/17 11:09
     * @return: void
     * @author: xjl
     */
    public static void bubbleSort(int[] array) {
        for (int i = array.length - 1; i > 0; i--) {
            for (int j = 0; j < i; j++) {
                if (gerater(array[j], array[j + 1])) {
                    swap(array, j, j + 1);
                }
            }
        }
    }

    public static boolean gerater(int v, int w) {
        return v - w > 0;
    }

    private static void swap(int[] arr, int i, int j) {
        int tmp = arr[i];
        arr[i] = arr[j];
        arr[j] = tmp;
    }

    public static void main(String[] args) {
        int[] array = new int[]{6, 1, 2, 7, 9, 3, 4, 5, 8};
        bubbleSort(array);
        System.out.println(Arrays.toString(array));
    }
}
